<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * 转入转出记录(充币提币记录)
 */
class Turn extends Model
{
    protected $table = 'turn';

    protected $fillable = [
        'id',
        'order_no', //订单号
        'uid', //用户id
        'cid', //币种id
        'price', //成交价
        'wallet_address', //钱包地址(充币时存系统钱包地址，提币时存用户钱包地址)
        'proc', //手续费
        'num', //数量
        'real_num', //实际数量
        'wallet_id', //系统钱包id
        'trade_time', //交易有效时间2小时
        'unlock_time', //钱包解锁时间8小时
        'type', //类型 1充币 2 提币
        'status', //状态 1 进行中 ，2成功， 3 失败 4 区块写入中
    ];

    const STATUS_ONE = 1;
    const STATUS_TWO = 2;
    const STATUS_THREE = 3;
    const STATUS_FOUR = 4;
    public static $STATUS = [
        self::STATUS_ONE => '进行中',
        self::STATUS_TWO => '完成',
        self::STATUS_THREE => '失败',
        self::STATUS_FOUR => '区块写入中',
    ];
    const type_a = 1;
    const type_b = 2;
    const type_c = 3;
    const type_d = 4;
    public static $type = [
        self::type_a => '转入',
        self::type_b => '转出',
        self::type_c => '转入',
        self::type_d => '转出',
    ];

    //关联用户
    public function user()
    {
        return $this->hasOne('App\\Models\\User', 'id', 'uid');
    }
    //关联币种
    public function currency()
    {
        return $this->hasOne('App\\Models\\Currency', 'id', 'cid');
    }
    //关联系统钱包
    public function wallet()
    {
        return $this->hasOne('App\\Models\\Wallet', 'id', 'wallet_id');
    }
}
